package thread;

import java.util.Random;
import java.util.concurrent.CountDownLatch;

public class ThreadDemo41 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);
        for(int i = 0; i < 10; i++){
            int id = i;
            Thread t = new Thread(() -> {
                Random random = new Random();
                int time = (random.nextInt(5) + 1) * 1000;
                System.out.println("开始下载" + id);
                try {
                    Thread.sleep(time);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("下载结束" + id);
                latch.countDown();
            });
            t.start();
        }
        latch.await();
        System.out.println("全部结束");
    }
}
